﻿using System;
using mojoPortal.Web;
using Resources;
using mojoPortal.Web.Framework;
using System.Collections;
using mojoPortal.Business;

namespace ud_ContactForm
{
    public partial class Finish : mojoBasePage
    {
        private int pageId = -1;
        private int moduleId = -1;
        ContactFormConfiguration config = new ContactFormConfiguration();

        void Page_Load(object sender, EventArgs e)
        {
            //if (!UserCanEditPage() || !UserCanViewPage())
            //{
            //    WebUtils.SetupRedirect(this, SiteRoot + "/AccessDenied.aspx");
            //}
            if (!Page.IsPostBack)
            {
                PopulateLabels();
            }
        }

        private void PopulateLabels()
        {
            Title = SiteUtils.FormatPageTitle(siteSettings, ContactFormResources.LabelFinishPage);
            moduleTitle.Header = ContactFormResources.LabelFinishPage;
            btnFinish.Text = ContactFormResources.ButtonFinish;
        }

        #region OnInit

        protected override void OnPreInit(EventArgs e)
        {
            AllowSkinOverride = true;
            base.OnPreInit(e);
            Load += Page_Load;
        }

        protected override void OnInit(EventArgs e)
        {
            LoadParams();
            LoadPanels();
            base.OnInit(e);
            btnFinish.Click += btnFinish_Click;
            SuppressPageMenu();
        }

        void btnFinish_Click(object sender, EventArgs e)
        {
            WebUtils.SetupRedirect(this, SiteUtils.GetCurrentPageUrl());
        }

        private void LoadParams()
        {
            pageId = WebUtils.ParseInt32FromQueryString("pageid", pageId);
            moduleId = WebUtils.ParseInt32FromQueryString("mid", true, moduleId);
        }

        private void LoadPanels()
        {
            Hashtable settings = ModuleSettings.GetModuleSettings(moduleId);
            config = new ContactFormConfiguration(settings);
            LoadSideContent(config.ShowLeftPanelSetting, config.ShowRightPanelSetting, config.ShowTopPanelSetting, config.ShowBottomPanelSetting, config.ContentPanelSetting);
        }
        #endregion
    }
}